package com.itbuka.goods.controller;

import com.itbuka.goods.domain.GoodsClassify;
import com.itbuka.entity.StatusCode;
import com.itbuka.goods.service.GoodsClassifyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.itbuka.entity.Result;
import com.itbuka.entity.PageResult;
import com.github.pagehelper.Page;

import java.util.List;

/**
 * 分类表
 */
@RestController
@RequestMapping("/GoodsClassify")
public class GoodsClassifyController {
    @Autowired
    private GoodsClassifyService goodsClassifyService;

    /**
     * 查询全部分类表
     */
    @GetMapping("/selectAll")
    public Result<List<GoodsClassify>> selectAll() {
        return Result.ok("查询成功", goodsClassifyService.selectAll());
    }

    /**
     * 条件查询分类表
     */
    @PostMapping("/selectList")
    public Result<List<GoodsClassify>> select(@RequestBody GoodsClassify iGoodsClassify) {
        return Result.ok("条件查询成功", goodsClassifyService.selectList(iGoodsClassify));
    }

    /**
     * 新增分类表
     */
    @PostMapping("/insert")
    public Result<?> insert(@RequestBody GoodsClassify iGoodsClassify) {
        goodsClassifyService.insert(iGoodsClassify);
        return Result.ok("新增成功");
    }

    /**
     * 删除分类表
     */
    @GetMapping("/delete")
    public Result<?> delete(@RequestParam String ids) {
        goodsClassifyService.delete(ids);
        return Result.ok("删除成功");
    }

    /**
     * 修改分类表
     */
    @PostMapping("/update")
    public Result<?> update(@RequestBody GoodsClassify iGoodsClassify) {
        goodsClassifyService.update(iGoodsClassify);
        return Result.ok("修改成功");
    }

    /**
     * 分页搜索实现分类表
     */
    @GetMapping(value = "/pageAll")
    public Result<?> pageAll(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page<GoodsClassify> pageList = goodsClassifyService.pageAll(page, size);
        PageResult<?> pageResult = new PageResult<>(pageList.getTotal(), pageList.getResult());
        return Result.ok("查询成功", pageResult);
    }

    /**
     * 分页条件搜索实现分类表
     */
    @GetMapping(value = "/pageList")
    public Result<?> pageList(@RequestBody GoodsClassify iGoodsClassify, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer size) {
        Page<GoodsClassify> pageList = goodsClassifyService.pageList(iGoodsClassify, page, size);
        PageResult<?> pageResult = new PageResult<>(pageList.getTotal(), pageList.getResult());
        return Result.ok("查询成功", pageResult);
    }

    /**
     * 分类启用、停用
     */
    @GetMapping("/status")
    public Result<?> status(@RequestParam Long id, @RequestParam Integer status) {
        Integer integer = goodsClassifyService.status(id, status);
        if (integer != 1) {
            return new Result<>(false, StatusCode.ERROR, "分类状态修改失败");
        }
        return new Result<>(true, StatusCode.OK, "分类状态修改成功");
    }
}




